import type { ConfigEnv } from 'vite'
import { loadEnv, defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import plainText from 'vite-plugin-plain-text'

import $ from 'jquery'

import { resolve } from 'path'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir)
}

// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv) => {
  const dirRoot = process.cwd()

  const env = loadEnv(mode, dirRoot)

  return defineConfig({
    base: env.VITE_PUBLIC_PATH,
    plugins: [
      vue(),
      plainText(/\.hbs$/)
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `$--color-primary: #2483ff;`,
        },
      },
    },
    server: {
      host: '0.0.0.0',
      port: 9095,
      // 反向代理
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:9005/demo/',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, 'api/')
        }
      }
    },
    resolve: {
      alias: {
        '@': pathResolve('./src'),
        'vue-i18n': pathResolve('./node_modules/vue-i18n/dist/vue-i18n.cjs.js'),
        '@ant-design/icons/lib/dist$': resolve(__dirname,'./src/utils/icon.js')
      },
    },
    define: {
      // setting vue-i18-next
      // Suppress warning
      __INTLIFY_PROD_DEVTOOLS__: false,
      //__DEV__: process.env.NODE_ENV !== 'production',//此行代码会引起ERROR：SyntaxError: Unexpected keyword 'false' (17:4) in K:/projects/基础框架和服务/source/v3.2.3/dayu-framework/dayu-appdemo-vue/node_modules/.pnpm/registry.nlark.com+warning@4.0.3/node_modules/warning/warning.js
    },
    optimizeDeps: {
      include: [

      ],
      exclude: [],
    },
    build: {
      sourcemap: false,
      outDir: 'website',
      rollupOptions: {
        input: {
          main: resolve(__dirname, 'index.html'),
        },
      },
    },
    esbuild: {
    },
  })
}

// https://vitejs.dev/config/
// export default defineConfig({
//   plugins: [vue()]
// })
